<?php

class OOWP_Atom_PostAuthor
    extends OOWP_Formattable
{

    public function __construct(array $args = array( ))
    {
        $input = array_merge(array(
            'formatting' => 'Posted by %s',
        ), $args);

        parent::__construct($input);
    }

    protected function getFormatting( )
    {
        return $this->dict['formatting'];
    }

    protected function setFormatting($format)
    {
        $this->dict['formatting'] = $format;
    }

    protected function getFormatPieces( )
    {
        $post = $this->governor->post;
        $author_name = get_the_author_meta('display_name', $post->post_author);
        $author_link = get_the_author_meta('url', $post->post_author);
        if ($author_link) {
            $result = '<a href="' . $author_link . '">' . $author_name . '</a>';
        } else {
            $result = $author_name;
        }
        return array(sprintf($this->formatting, $result));
    }

}
